#include "../include/header.h"


struct ListNode {
    char nKey;
    ListNode * pNext;
};


ListNode* FindK(ListNode* head, int k)
{
    if (NULL == head || k < 1)
        return NULL;

    ListNode *p1, *p2;
    p1 = head;
    p2 = head;
    int i = 1;

    while (NULL != p1 && i <= k)
    {
        i++;
        p1 = p1->pNext;
    }

    while(NULL != p1)
    {
        p1 = p1->pNext;
        p2 = p2->pNext;
    }

    return p2;
}


void TestForThirteen()
{
   char c;
   ListNode *head = (ListNode*)malloc(sizeof(ListNode));
    head->pNext = NULL;
   ListNode  *p = head, *q = NULL;
    while(c !='0')
    {
        c = getchar();
        q = (ListNode*)malloc(sizeof(ListNode));
        q->nKey = c;
        q->pNext = NULL;
        p->pNext = q;
        p = p->pNext;

    }
    cout<<"---------------"<<endl;
    cout<<FindK(head, 3)->nKey<<endl;
}
